<template>
	<view class="index tn-safe-area-inset-bottom ">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed :isBack="false" :bottomShadow="false" backgroundColor="#FFFFFF">
			<view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-left">
				<!-- 图标logo -->
				<view class="custom-nav__back" @click="tn('')">
					<view class="logo-pic" style="background-image:url('../static/logo.png')">
						<view class="logo-image">
						</view>
					</view>
				</view>
				<!-- 搜索框 -->
				<view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center" @click="">
					<view class="custom-nav__search__box tn-flex tn-flex-col-center tn-flex-row-left"
						style="background-color: rgba(230,230,230,0.3);">
						<view class="custom-nav__search__icon tn-icon-search tn-color-gray"></view>
						<view class="custom-nav__search__text tn-padding-left-xs tn-color-gray"> 
							<tn-input placeholder="请输入名称,ID,标题,内容" name="input" v-model="search" inputAlign="left"
								@input="loadDate(0,100,0)"></tn-input>
						</view>
					</view>
				</view>
			</view>
		</tn-nav-bar>

		<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top"
			:style="{paddingTop: vuex_custom_bar_height-35 + 'px'}">

		</view>

		<swiper class="card-swiper" @click="gotoInfo" :circular="true" :autoplay="true" duration="500" interval="8000"
			@change="cardSwiper">
			<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
				<!-- <view class="swiper-item image-banner">
          <image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
        </view> -->
				<view class="swiper-item image-banner"
					:style="'background-image:url('+ item.url + ');background-size: cover;border-radius: 15rpx;'">
				</view>
				<view class="swiper-item-text">
					<view class="tn-text-bold tn-color-white" style="font-size: 50rpx;">{{item.title}}</view>
					<view class="tn-color-white tn-padding-top" style="font-size: 30rpx;">{{item.name}}</view>
					<view class="tn-text-sm tn-text-bold tn-color-white tn-padding-top-sm tn-padding-bottom-sm">
						{{item.text}}
					</view>
				</view>
			</swiper-item>
		</swiper>
		<view class="indication">
			<block v-for="(item,index) in swiperList" :key="index">
				<view class="spot" :class="cardCur==index?'active':''"></view>
			</block>
		</view>



		<view class="tn-padding-bottom-lg" style="margin-top: -45rpx;">
			<view class="tn-margin-top-sm">
				<tn-sticky :offsetTop="0" :customNavHeight="vuex_custom_bar_height">
					<view class="button-vip tn-flex tn-flex-row-between tn-flex-col-center tn-shadow-blur">
						<view class="tn-margin-left" >
							<tn-tabs :list="fixedList" :current="current" :isScroll="true" activeColor="#000" :bold="true"
								:fontSize="32" :badgeOffset="[20, 50]" @change="tabChange" backgroundColor="#FFFFFF99"
								:height="110"></tn-tabs>
						</view>
						<view class="tn-margin-right">
							<tn-button backgroundColor="#D3E6FF" fontColor="#3C8EFF" padding="10rpx 0" width="160rpx"
								@click="tn('/messagePages/blackList')">
								<text class="tn-text-bold">曝光名单</text>
							</tn-button>
						</view>
					</view>
				</tn-sticky>
			</view>
			<view class="" v-if="current==0 || current==1">

				<view class="tn-flex tn-flex-direction-column tn-margin-top-sm tn-margin-bottom">
					<block v-for="(item,index) in content">
						<view class="blogger__item" :key="index">
							<view class="blogger__author tn-flex tn-flex-row-between tn-flex-col-center">
								<view class="justify__author__info" @click="toDetails(item)">
									<view class="tn-flex tn-flex-row-center">
										<view class="tn-flex tn-flex-row-center tn-flex-col-center">
											<view class="">
												<tn-avatar
												  class=""
												  shape="circle"
												  :src="item.avatar"
												  size="lg">
												</tn-avatar>
											</view>
											<view class="tn-padding-right tn-text-ellipsis">
												<view
													class="tn-padding-right tn-padding-left-sm tn-text-bold tn-text-lg">
													{{ item.userName }}({{item.newUserId}})
												</view>
												<view
													class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray">
													{{ item.createTime }}
												</view>
											</view>
										</view>
									</view>
								</view>
								<view
									class="blogger__author__btn justify-content-item tn-flex-col-center tn-flex-row-center">
									<!-- 为什么不放关注按钮，因为快餐文化的世界，关注按钮放在外面没必要 -->
									<text class="tn-icon-more-vertical tn-color-gray tn-text-bold tn-text-xxl"></text>
								</view>
							</view>

							<view
								class="blogger__desc tn-margin-top-sm tn-margin-bottom-sm tn-text-justify tn-flex-col-center tn-flex-row-left"
								@click="toDetails(item)">
								<view v-for="(label_item,label_index) in item.label" :key="label_index"
									class="blogger__desc__label tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
									<text class="blogger__desc__label--prefix">#</text>
									<text class="tn-text-df">{{ label_item }}</text>
								</view>
								<!-- 不用限制长度了，因为发布的时候限制长度了-->
								<text v-if="!item.label || item.label.length < 4"
									class="blogger__desc__content tn-flex-1 tn-text-justify tn-text-df">{{ item.title }}</text>
							</view>

							<!-- 内容太多疲劳了-->
							<!-- <view
             v-if="item.content"
             class="blogger__content"
             :id="`blogger__content--${index}`"
           >
             <view
               class="blogger__content__data clamp-text-2">
               {{ item.content }}
             </view>
           </view> -->

							<block v-if="item.imgs">
								<view v-if="[1,2,4].indexOf(item.imgs.imgsSize) != -1" class="tn-padding-top-xs"
									 @click="toDetails(item)">
									<image v-for="(image_item,image_index) in item.imgs" :key="image_index"
										class="blogger__main-image" :class="{
                   'blogger__main-image--1 tn-margin-bottom-sm': item.mainImage.length === 1,
                   'blogger__main-image--2 tn-margin-right-sm tn-margin-bottom-sm': item.mainImage.length === 2 || item.mainImage.length === 4
                 }" :src="image_item" mode="aspectFill"></image>
								</view>
								<view v-else class="tn-padding-top-xs"  @click="toDetails(item)">
									<tn-grid hoverClass="none" :col="3">
										<block v-for="(image_item,image_index) in item.imgs" :key="image_index">
											<!-- #ifndef MP-WEIXIN -->
											<tn-grid-item style="width: 30%;margin: 10rpx;">
												<image class="blogger__main-image blogger__main-image--3"
													:src="image_item" mode="aspectFill"></image>
											</tn-grid-item>
											<!-- #endif-->
											<!-- #ifdef MP-WEIXIN -->
											<tn-grid-item style="width: 30%;margin: 10rpx;">
												<image class="blogger__main-image blogger__main-image--3"
													:src="image_item" mode="aspectFill"></image>
											</tn-grid-item>
											<!-- #endif-->
										</block>
									</tn-grid>
								</view>
							</block>

							<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top-xs">
								<view class="justify-content-item tn-color-gray tn-text-center">
									<view class="">
										<text class="blogger__count-icon tn-icon-footprint"></text>
										<text class="tn-padding-right">{{ item.readNum }}</text>
									</view>
								</view>
								<view class="justify-content-item tn-flex tn-flex-col-center">

								</view>
							</view>
						</view>

						<!-- 边距间隔 -->
						<view class="tn-strip-bottom" v-if="index != content.length - 1"></view>
					</block>
				</view>
			</view>


			<view class="" v-if="current==2">
				<view class="" style="padding: 30rpx 20rpx;">
					<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
						<text class="tn-icon-wea-wind tn-color-gray--light"></text>
					</view>
					<view class="tn-color-gray--disabled tn-text-center tn-text-lg">请搜索内容！</view>
				</view>
			</view>

		</view>

		<view class='tn-tabbar-height'></view>



	</view>
</template>



<script>
	import request from '@/common/request.js'
	export default {
		name: 'Index',
		data() {
			return {
				cardCur: 0,
				isAndroid: true,
				swiperList: [],
				/* tabs*/
				current: 0,
				fixedList: [{
						name: '最新'
					},
					{
						name: '阅读量'
					},
				],

				/* 瀑布流*/
				loadStatus: 'loadmore',
				list: [],
				data: [],
				content: [],
				search:'',
				pageNum: 1,
				pageSize: 100,
			}
		},

		created() {
			const systemInfo = uni.getSystemInfoSync()
			if (systemInfo.system.toLocaleLowerCase().includes('ios')) {
				this.isAndroid = false
			} else {
				this.isAndroid = true
			}
			this.getRandomData()
		},
		onReachBottom() {

		},
		mounted() {
			this.loadDate()
			this.localBannerr()
		},
		methods: {
			loadDate() {
				let that = this ;
			
				request.get("/xxc/news/list", {
					state: '2',
					type: this.current,
					keyWord:this.search,
					pageNum: this.pageNum,
					pageSize: this.pageSize,
				}).then((res) => {
					this.list = [];
					let result = [];
					let arrayData = res.rows;
					for (let i = 0; i < arrayData.length; i++) {
						let temp = arrayData[i];
						let resTemp = new Array();
						if (temp.img != null) {
							let tempImg = temp.img.split(',');
							for (let z = 0; z < tempImg.length; z++) {
								resTemp.push(request.getBaseUrl() + tempImg[z]);
							}
							temp['imgs'] = resTemp;
							temp['imgsSize'] = resTemp.length;
						}
						result.push(temp);
					}
					this.content = result;
				});
			},
			localBannerr(){
				request.get("/xcx/banner/list", {
					state: 'Y',
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					type:1
				}).then((res) => {
					let arrayData = res.rows;
					for (let i = 0; i < arrayData.length; i++) {
						let temp = arrayData[i];
						let resTemp = new Array();
						if (temp.img != null) {							
							temp["id"] = temp.id;
							temp['type'] = "image";
							temp['url'] = request.getBaseUrl() + temp.img;
							temp['title'] = ' ';
							temp['name'] = ' ';
							temp['text'] = ' ';
						}
						this.swiperList.push(temp);
					}
				});
			},
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			gotoInfo(){
				uni.navigateTo({
					url: "/circlePages/bannerNew?url=" + this.swiperList[this.cardCur].herf,
				});	
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			// tab选项卡切换
			tabChange(index) {
				this.current = index
				this.loadDate();
			},
			/* 瀑布流*/
			// 获取随机数据
			getRandomData() {

			},
			// 瀑布流加载完毕事件
			handleWaterFallFinish() {
				this.loadStatus = 'nomore'
			},
			// 获取价格整数和小数部分
			getPrice(price) {
				const priceStr = String(price)
				if (priceStr.indexOf('.') !== -1) {
					return priceStr.split('.')
				} else {
					return [priceStr, '00']
				}
			},
			toDetails(item){
			
				request.get("/xxc/news/readNum/"+item.id).then((res) => {
					if(item.gzhNew == 'Y'){
						uni.navigateTo({
							url: "/circlePages/gzhNew?info=" + JSON.stringify(item),
						});
					}else{
						uni.navigateTo({
							url: "/circlePages/details?info=" + JSON.stringify(item),
						});
					}
				});
				
			}

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		max-height: 100vh;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}

	/* 轮播视觉差 start */
	.card-swiper {
		height: 330rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		padding: 40rpx 30rpx 30rpx 30rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		border-radius: 15rpx;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		// overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
	}

	.card-swiper swiper-item .swiper-item-text {
		margin-top: -160rpx;
		text-align: center;
		width: 100%;
		display: block;
		height: 50%;
		border-radius: 10rpx;
		transform: translate(100rpx, -60rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item-text {
		margin-top: -220rpx;
		width: 100%;
		transform: translate(0rpx, 0rpx) scale(0.9, 0.9);
		transition: all 0.6s ease 0s;
	}

	.image-banner {
		border: 1rpx solid #F8F7F8;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		//z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.6;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		top: -70rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #FFFFFF;
	}



	/* 图标容器12 start */
	.tn-three {
		position: absolute;
		top: 50%;
		right: 50%;
		bottom: 50%;
		left: 50%;
		transform: translate(-38rpx, -20rpx) rotateX(20deg) rotateY(10deg) rotateZ(-20deg);
		text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
	}

	.icon12 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg6.png);


				}
			}
		}
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			margin-left: 30rpx;
			flex-basis: 5%;
		}

		&__search {
			flex-basis: 60%;
			width: 100%;
			height: 100%;

			&__box {
				width: 100%;
				height: 70%;
				padding: 10rpx 0;
				margin: 0 30rpx;
				border-radius: 60rpx 60rpx 0 60rpx;
				font-size: 24rpx;
			}

			&__icon {
				padding-right: 10rpx;
				margin-left: 20rpx;
				font-size: 30rpx;
			}

			&__text {
				// color: #AAAAAA;
			}
		}
	}

	.logo-image {
		width: 65rpx;
		height: 65rpx;
		position: relative;
		border: 1rpx solid #F8F7F8;
		border-radius: 50%;
	}

	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 50%;
	}

	/* 自定义导航栏内容 end */


	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/

	/* 文章内容 start*/
	.blogger {
		&__item {
			padding: 30rpx;
		}

		&__author {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}

		&__desc {
			line-height: 55rpx;

			&__label {
				padding: 0 20rpx;
				margin: 0rpx 18rpx 0 0;

				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}

			&__content {}
		}

		&__content {
			margin-top: 18rpx;
			padding-right: 18rpx;

			&__data {
				line-height: 46rpx;
				text-align: justify;
				overflow: hidden;
				transition: all 0.25s ease-in-out;

			}

			&__status {
				margin-top: 10rpx;
				font-size: 26rpx;
				color: #82B2FF;
			}
		}

		&__main-image {
			border-radius: 16rpx;

			&--1 {
				max-width: 80%;
				max-height: 300rpx;
			}

			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}

			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}

		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}

		&__ad {
			width: 100%;
			height: 500rpx;
			transform: translate3d(0px, 0px, 0px) !important;

			::v-deep .uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}

			.uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}

			&__item {
				position: absolute;
				width: 100%;
				height: 100%;
				transform-origin: left center;
				transform: translate3d(100%, 0px, 0px) scale(1) !important;
				transition: transform 0.25s ease-in-out;
				z-index: 1;

				&--0 {
					transform: translate3d(0%, 0px, 0px) scale(1) !important;
					z-index: 4;
				}

				&--1 {
					transform: translate3d(13%, 0px, 0px) scale(0.9) !important;
					z-index: 3;
				}

				&--2 {
					transform: translate3d(26%, 0px, 0px) scale(0.8) !important;
					z-index: 2;
				}
			}

			&__content {
				border-radius: 40rpx;
				width: 640rpx;
				height: 500rpx;
				overflow: hidden;
			}

			&__image {
				width: 100%;
				height: 100%;
			}
		}
	}

	/* 文章内容 end*/
</style>